<?php
namespace app\api\controller\v1;

use app\api\model\Cart as  Carts;
use think\Request;

class Cart extends Base
{

    public function index(Carts $cart,Request $request)
    {
        $token = $request->header('token');

        $cart = $cart->lists($token);

        return $this->success($cart);

    }

    public function addCart(Carts $cart,Request $request)
    {

        $data = $request->except('version');

        $token = $request->header('token');

        $cart = $cart->add($token,$data);

        if ($cart) {

            return $this->success();

        }

        return $this->error();
    }

    public function counts(Carts $cart,Request $request)
    {
        $data = $request->except('version');

        $cart = $cart->changeCounts($data);

        if ($cart){

            return $this->success();
        }

        return $this->error();

    }

    public function delCart($id)
    {

        $cart = Carts::destroy($id);

        if ($cart){

            return $this->success();
        }

        return $this->error();


    }

}
